{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "066e0563",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Tree"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "d22a495c",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = [\n",
    "    {\n",
    "        'children':[\n",
    "            {'name': '叔叔'},\n",
    "            {\n",
    "                'children': [{'name': '小红'}],\n",
    "                'name': '伯伯'\n",
    "            },\n",
    "            {\n",
    "                'name': '父亲',\n",
    "                'children': [\n",
    "                    {'name': '我'},\n",
    "                    {'name': '姐姐'}\n",
    "                ]\n",
    "            }\n",
    "            \n",
    "        ],\n",
    "        'name': \"祖父母\"\n",
    "    }\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "1cc52e79",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"cf6219c3ecac44fb9bd937e484af0238\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_cf6219c3ecac44fb9bd937e484af0238 = echarts.init(\n",
       "                    document.getElementById('cf6219c3ecac44fb9bd937e484af0238'), 'white', {renderer: 'canvas'});\n",
       "                var option_cf6219c3ecac44fb9bd937e484af0238 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"tree\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"children\": [\n",
       "                        {\n",
       "                            \"name\": \"\\u53d4\\u53d4\"\n",
       "                        },\n",
       "                        {\n",
       "                            \"children\": [\n",
       "                                {\n",
       "                                    \"name\": \"\\u5c0f\\u7ea2\"\n",
       "                                }\n",
       "                            ],\n",
       "                            \"name\": \"\\u4f2f\\u4f2f\"\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u7236\\u4eb2\",\n",
       "                            \"children\": [\n",
       "                                {\n",
       "                                    \"name\": \"\\u6211\"\n",
       "                                },\n",
       "                                {\n",
       "                                    \"name\": \"\\u59d0\\u59d0\"\n",
       "                                }\n",
       "                            ]\n",
       "                        }\n",
       "                    ],\n",
       "                    \"name\": \"\\u7956\\u7236\\u6bcd\"\n",
       "                }\n",
       "            ],\n",
       "            \"symbol\": \"emptyCircle\",\n",
       "            \"symbolSize\": 7,\n",
       "            \"edgeShape\": \"curve\",\n",
       "            \"edgeForkPosition\": \"50%\",\n",
       "            \"roam\": false,\n",
       "            \"expandAndCollapse\": true,\n",
       "            \"layout\": \"orthogonal\",\n",
       "            \"orient\": \"LR\",\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"leaves\": {\n",
       "                \"label\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": \"top\",\n",
       "                    \"margin\": 8\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [],\n",
       "            \"selected\": {},\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u6811\\u56fe\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_cf6219c3ecac44fb9bd937e484af0238.setOption(option_cf6219c3ecac44fb9bd937e484af0238);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x16b248a58b0>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = (\n",
    "    Tree()\n",
    "    .add('', data)\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title='树图')\n",
    "    )\n",
    ")\n",
    "c.render_notebook()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
